
public class NaiveBayesClassifier {
    public static int FOLD_COUNT = 1;
    
    public static void doClassify(String data, AbstractClassifier classifier) throws Exception
    {
		double[] accuracies = new double[FOLD_COUNT];
	    
	    for(int foldIndex=0; foldIndex<FOLD_COUNT; foldIndex++)
	    {
	    	classifier.initialize(foldIndex, FOLD_COUNT);
	    	classifier.train();
	    	accuracies[foldIndex] = classifier.test();
	    }
	    
	    double accuracySum = 0.0;
	    for(int foldIndex=0; foldIndex<FOLD_COUNT; foldIndex++)
	    	accuracySum += accuracies[foldIndex];
	    double accuracyAverage = accuracySum / FOLD_COUNT;
	    
	  	System.err.format("Accuracy (average) : %2.2f\n", accuracyAverage*100);
    }
    
	public static void doBinomial(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.BINOMIAL, NBClassifier.FeatureSelectionMethod.NONE
	    ));
	}
	    
	public static void doBinomialChi2(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.BINOMIAL, NBClassifier.FeatureSelectionMethod.CHI
	    ));
	}
	    
	public static void doMultinomial(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.MULTINOMIAL, NBClassifier.FeatureSelectionMethod.NONE
	    ));
	}
	
	public static void doMultinomialChi2(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.MULTINOMIAL, NBClassifier.FeatureSelectionMethod.CHI
	    ));
	}
	
	public static void doMultinomialKL(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.MULTINOMIAL, NBClassifier.FeatureSelectionMethod.KL
	    ));
	}
	
	public static void doMultinomialdKL(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.MULTINOMIAL, NBClassifier.FeatureSelectionMethod.dKL
	    ));
	}
	    
	public static void doTWCNB(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.TRANSFORMED_WEIGHT_COMPLEMENT, NBClassifier.FeatureSelectionMethod.NONE
	    ));	
	}
	
	public static void doWCNB(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.WEIGHT_COMPLEMENT, NBClassifier.FeatureSelectionMethod.NONE
	    ));	
	}
	
	public static void doCNB(String data) throws Exception {
		doClassify(data, new NBClassifier(
	    	data, NBClassifier.ClassifierType.COMPLEMENT, NBClassifier.FeatureSelectionMethod.NONE
	    ));
	}
	
	public static void doSVM(String data) throws Exception{
		/*
		doClassify(data, new SVMClassifier(
	    	data, SVMClassifier.FeatureSelectionMethod.CHI
	    ));
	    */
	}
	    
	public static void outputProbability( final double[] probability )
	{
		for ( int i = 0; i < probability.length; i ++ )
	    {
	  	    if ( i == 0 )
		  		System.out.format( "%1.8g", probability[i] );
	  		else
		  		System.out.format( "\t%1.8g", probability[i] );
	  	}
	  	System.out.format( "\n" );
    }
    
    public static void main(String args[]) throws Exception {
	    if (args.length != 2) {
	        System.err.println("Usage: NaiveBayesClassifier <mode> <train>");
	        System.exit(-1);
	    }
	      
	    String mode = args[0];
	    String data = args[1];
	      
	    if (mode.equals("binomial")) {
	        doBinomial(data);
	    } else if (mode.equals("binomial-chi2")) {
	        doBinomialChi2(data);
	    } else if (mode.equals("multinomial")) {
	        doMultinomial(data);
	    } else if (mode.equals("multinomial-chi2")) {
	        doMultinomialChi2(data);
	    } else if (mode.equals("multinomial-kl")) {
	        doMultinomialKL(data);
	    } else if (mode.equals("multinomial-dkl")) {
	        doMultinomialdKL(data);
	    } else if (mode.equals("twcnb")) {
	        doTWCNB(data);
	    } else if (mode.equals("wcnb")) {
	        doWCNB(data);
	    } else if (mode.equals("cnb")) {
	        doCNB(data);
	    } else if (mode.equals("svm")) {
	        doSVM(data);
	    } else { 
	        // Add other test cases that you want to run here.
	        
	        System.err.println("Unknown mode "+mode);
	        System.exit(-1);
	    }
    }
}